package com.jeasonzhao.report.exceptions;

import com.jeasonzhao.commons.parser.lex.LexToken;
import com.jeasonzhao.report.model.Report;
import com.jeasonzhao.report.model.ReportColumn;
import com.jeasonzhao.report.model.ReportParam;
import com.jeasonzhao.report.msg.Message;

public abstract class ReportException extends SQLReportException
{
    /**
     *
     */
    private static final long serialVersionUID = 1L;

    public ReportException(Object ...objs)
    {
        super(objs);
    }

    public ReportException(Throwable t,Object ...objs)
    {
        super(t,objs);
    }

    @Message(
        {"zh_cn","{0}，配置报表错误，数据源参数\"{1}\"没有被映射"})
    public static class UnmappedParameter extends ReportException
    {
        /**
         *
         */
        private static final long serialVersionUID = 1L;

        public UnmappedParameter(Report report,String strParameterName)
        {
            super(report,strParameterName);
        }
    }

    @Message(
        {"zh_cn","{0}报表定义错误，SQL中多选参数{1}不能够在首位"})
    public static class MultiParamAtBegin extends ReportException
    {
        /**
         *
         */
        private static final long serialVersionUID = 1L;

        public MultiParamAtBegin(Report report,ReportParam param,LexToken token)
        {
            super(report,param);
        }
    }

    @Message(
        {"zh_cn","{0}报表定义错误，SQL中可选参数{1}不能够在首位"})
    public static class OptParamAtBegin extends ReportException
    {
        /**
         *
         */
        private static final long serialVersionUID = 1L;

        public OptParamAtBegin(Report report,ReportParam param,LexToken token)
        {
            super(report,param);
        }
    }

    @Message(
        {"zh_cn","{0}括号不匹配"})
    public static class UnmatchedBracket extends ReportException
    {
        /**
         *
         */
        private static final long serialVersionUID = 1L;

        public UnmatchedBracket(Report report,LexToken token)
        {
            super(report);
        }
    }

    @Message(
        {"zh_cn","{0}参数{1}作为多选值存在的时候前导操作符号{2}不合法"})
    public static class MultiParamOperatorError extends ReportException
    {
        /**
         *
         */
        private static final long serialVersionUID = 1L;

        public MultiParamOperatorError(Report report,LexToken token,LexToken tkOperator)
        {
            super(report,token.getToken(),tkOperator.getToken());
        }
    }

    public static class SqlParseError extends ReportException
    {
        /**
         *
         */
        private static final long serialVersionUID = 1L;

        public SqlParseError(Report report)
        {
            super(report);
        }
    }

    @Message(
        {"zh_cn","{0}:列{1}没有生成唯一标示"
        ,"en","{0}:No GUID generated for the column {1}"})
    public static class ColumnNoGuid extends ReportException
    {
        /**
         *
         */
        private static final long serialVersionUID = 1L;

        public ColumnNoGuid(Report report,ReportColumn col)
        {
            super(report,col);
        }
    }

    @Message(
        {"zh_cn","{0}:列\"{1}\"的唯一编码(GUID)\"{2}\"和本报表中的其他列的唯一编码重复"
        ,"en","{0}: the GUID of the column {1} is not unique in all of columns belongs to this report."})
    public static class ColumnDuplicatedGuid extends ReportException
    {
        /**
         *
         */
        private static final long serialVersionUID = 1L;

        public ColumnDuplicatedGuid(Report report,ReportColumn col)
        {
            super(report,col,null == col ? null : col.getGuid());
        }
    }

    @Message(
        {"zh_cn","{0}:找不到父亲级报表的定义，父亲报表代码为：{1}"
        ,"en","{0}: Could not found the parent-report whose identifier is {1}"})
    public static class CouldNotFoundParent extends ReportException
    {
        /**
         *
         */
        private static final long serialVersionUID = 1L;

        public CouldNotFoundParent(Report report)
        {
            super(report,null == report ? null : report.getParentReportId());
        }
    }

    @Message(
        {"zh_cn","{0}:没有设置数据提供者的类"
        ,"en","{0}: No dataset-provider has been set"})
    public static class NoDataSetProviderClass extends ReportException
    {
        /**
         *
         */
        private static final long serialVersionUID = 1L;

        public NoDataSetProviderClass(Report report)
        {
            super(report);
        }

    }

    @Message(
        {"zh_cn","{0}:未知的数据提供者类型 {1}"
        ,"en","{0}: Unknown dataset-provider {1}"})
    public static class UnknownDatasetProvider extends ReportException
    {
        /**
         *
         */
        private static final long serialVersionUID = 1L;

        public UnknownDatasetProvider(Report report)
        {
            super(report,null == report ? "[NULL]" : report.getDataSetProviderType());
        }

    }

    @Message(
        {"zh_cn","{0}配置的类{1}不正确，类不能转换为{2}"
        ,"en","{0} Configuration Error, can not convert the class {1} to {2}"
    })
    public static class CastError extends ReportException
    {
        /**
         *
         */
        private static final long serialVersionUID = 1L;

        public CastError(Report dict,String strClassName,Class<?> destinationClass)
        {
            super(dict,strClassName
                  ,null == destinationClass ? "[Unknown destination]" : destinationClass.getName());
        }

        public CastError(Report dict,String strClassName,Class<?> destinationClass,Throwable t)
        {
            super(t,dict,strClassName
                  ,null == destinationClass ? "[Unknown destination]" : destinationClass.getName());
        }

    }

}
